package com.db.compare.emum;

import java.util.Optional;

public enum SyncEnum {

    PUBREF(1,"pubref","pub_ref"),BILLBASE(2,"billnumlist","bill_base"),
    TEMPLATE(3,"billtem","billtemplate_base"),ENTITY(4,"entity","billentity_base"),
    GROUPTPL(5,"group","billtplgroup_base"),BILLITEM(6,"billitem","billitem_base"),
    FILTER(7,"filter","pb_meta_filters"),FILTERITEM(8,"fileritem","pb_meta_filter_item"),
    SOLUTION(9,"solution","pb_filter_solution"),SOLUTIONITEM(10,"solutionitem","pb_filter_solution_common"),
    TOOL(11,"toolbar","bill_toolbar"),TOOLITEM(12,"toolitem","bill_toolbaritem"),
    COMMAND(13,"command","bill_command"),RULE(14,"ruleregister","billruleregister");

    private String code;
    private int type;
    private String tableName;
    SyncEnum(int type,String code,String tableName){
        this.type=type;
        this.code = code;
        this.tableName=tableName;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public static int getTypeByCode(String code){
        Optional<SyncEnum> m1 = EnumUtil.getEnumObject(SyncEnum.class, e -> e.code.equals(code));
        return m1.isPresent() ? m1.get().getType(): 0;
    }

    public static String getCodeByType(int type){
        Optional<SyncEnum> m1 = EnumUtil.getEnumObject(SyncEnum.class, e -> e.getType()==type);
        return m1.isPresent() ? m1.get().getCode() : "";
    }

    public static String getTableByCode(String code){
        Optional<SyncEnum> m1 = EnumUtil.getEnumObject(SyncEnum.class, e ->  e.code.equals(code));
        return m1.isPresent() ? m1.get().tableName : "";
    }

}
